﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ddcCajamarca.BusinessEntities.Directorio;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace ddcCajamarca.Repository.Mapping
{
    public class PersonaMap : EntityTypeConfiguration<Persona>
    {
        public PersonaMap()
        {
            this.HasKey(c => c.Id);

            this.Property(c => c.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(c => c.idTipoDoc)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.idUbigeo)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.idProfesion)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.idVocativo)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.NombreArtistico)
                .HasMaxLength(75)
                .IsOptional();

            this.Property(c => c.Nombre)
                .HasMaxLength(125)
                .IsRequired();

            this.Property(c => c.Apellidos)
                .HasMaxLength(125)
                .IsRequired();

            this.Property(c => c.NumeroDocumento)
                .HasMaxLength(20)
                .IsOptional();

            this.Property(c => c.Direccion)
                .HasMaxLength(250)
                .IsOptional();

            this.Property(c => c.Direccion2)
                .HasMaxLength(250)
                .IsOptional();

            this.Property(c => c.Telefono)
                .HasMaxLength(10)
                .IsRequired();

            this.Property(c => c.Telefono2)
                .HasMaxLength(10)
                .IsOptional();

            this.Property(c => c.Telefono3)
                .HasMaxLength(10)
                .IsOptional();

            this.Property(c => c.FechaNac)
                .HasColumnType("datetime2")
                .HasPrecision(7)
                .IsOptional();

            this.Property(c => c.FechaReg)
                .HasColumnType("datetime2")
                .HasPrecision(7)
                .IsRequired();

            this.Property(c => c.Email)
                .HasMaxLength(100)
                .IsOptional();

            this.Property(c => c.PaginaWeb)
                .HasMaxLength(500)
                .IsOptional();

            this.Property(c => c.Autoridad)
                .IsOptional();

            this.Property(c => c.Imagen)
                .HasMaxLength(500)
                .IsOptional();

            this.ToTable("Persona");
            this.Property(c => c.Id).HasColumnName("Id");
            this.Property(c => c.idTipoDoc).HasColumnName("idTipoDoc");
            this.Property(c => c.idUbigeo).HasColumnName("idUbigeo");
            this.Property(c => c.idProfesion).HasColumnName("idProfesion");
            this.Property(c => c.idVocativo).HasColumnName("idVocativo");
            this.Property(c => c.NombreArtistico).HasColumnName("NombreArtistico");
            this.Property(c => c.Nombre).HasColumnName("Nombre");
            this.Property(c => c.Apellidos).HasColumnName("Apellidos");
            this.Property(c => c.NumeroDocumento).HasColumnName("NumeroDocumento");
            this.Property(c => c.Direccion).HasColumnName("Direccion");
            this.Property(c => c.Direccion2).HasColumnName("Direccion2");
            this.Property(c => c.Telefono).HasColumnName("Telefono");
            this.Property(c => c.Telefono2).HasColumnName("Telefono2");
            this.Property(c => c.Telefono3).HasColumnName("Telefono3");
            this.Property(c => c.FechaNac).HasColumnName("FechaNac");
            this.Property(c => c.FechaReg).HasColumnName("FechaReg");
            this.Property(c => c.Email).HasColumnName("Email");
            this.Property(c => c.PaginaWeb).HasColumnName("PaginaWeb");
            this.Property(c => c.Autoridad).HasColumnName("Autoridad");
            this.Property(c => c.Imagen).HasColumnName("Imagen");

            this.HasRequired(c => c.TipoDocumento)
                .WithMany(c => c.Personas)
                .HasForeignKey(t => t.idTipoDoc)
                .WillCascadeOnDelete(false);

            this.HasRequired(c => c.Ubigeo)
                .WithMany(c => c.Personas)
                .HasForeignKey(t => t.idUbigeo)
                .WillCascadeOnDelete(false);

            this.HasOptional(c => c.Profesion)
                .WithMany(c => c.Personas)
                .HasForeignKey(t => t.idProfesion)
                .WillCascadeOnDelete(false);

            this.HasOptional(c => c.Vocativo)
                .WithMany(c => c.Personas)
                .HasForeignKey(t => t.idVocativo)
                .WillCascadeOnDelete(false);
        }
    }
}
